<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow = !isShow">显示/隐藏</button>
    <home-page v-if="isShow"></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data() {
        return {
          isShow: true
        }
      },
    });
    const HomePage = {
      template: `
        <div>
          <h2 ref="title">home页</h2>  
          <button @click="addLi">增加li</button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{item}}  
            </li>  
          </ul>
        </div>
      `,
      data() {
        return {
          msg: '组件数据',
          arr: [1,2,3,4]
        }
      },
      methods: {
        addLi() {
          this.arr.push(this.arr.length+1);
        }
      },
      beforeCreate() {
        console.log('beforeCreate触发');
        
      },
      created () {
        console.log('created触发');
        
      },
      beforeMount() {
        console.log('beforeMount触发');
       
      },
      mounted() {
        console.log('mounted触发');
        
      },
      beforeUpdate () {
        console.log('数据更新之前-beforeUpdate');
        
      },
      updated(){
        console.log('数据更新完成,updated');
        console.log(this.$refs.oul.children);
      },
      beforeUnmount() {
        console.log('组件卸载之前');
      },
      unmounted() {
        console.log('组件卸载完成');
      }
    }

    app.component('HomePage', HomePage)
    app.mount('#app')
  </script>
</body>
</html>